/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Controller;

import GUI.EnigmaGUIMainWindow;
import GUI.EnigmaPreferences;
import Model.EnigmaModel;
import Model.GameStateListener;
import java.io.File;
import java.io.IOException;

/**
 *
 * @author Snowangelic
 */
public class NormalGameController extends EnigmaController implements GameStateListener {

    ReplaySaver replay;

    public NormalGameController(EnigmaModel model,EnigmaGUIMainWindow gui,File level) throws IOException{
        this.model=model;
        this.gui=gui;
        gui.setController(this);
        model.addGameStateListener(this);
        replay=new ReplaySaver();
        replay.setLevelFile(level);
    }

    @Override
    public void keyPressed(int keyCode) {
        if(keyCode==EnigmaPreferences.getInstance().getPauseKeyCode())
            model.pauseGame();
    }

    public void gameStateChanged(int newGameState) {
        replay.setGameState(newGameState);
    }

    @Override
    public void mouseMoved(MouseMovedCommand mouseMovedCommand) {
        int x=mouseMovedCommand.getXPos();
        int y=mouseMovedCommand.getYPos();
        if(x!=-1 || y!=-58){
            x+=1;
            y+=58;
            System.out.println(x+" et "+y);
            mouseX=mouseX+x;
            mouseY=mouseY+y;
            int[] coords=new int[2];
            coords[0]=x;
            coords[1]=y;
            replay.mouseMoved(coords);
        }
    }

    @Override
    public void scrollInventory(ScrollInventoryCommand scrollInventoryCommand) {
        replay.inventoryScrolled();
        model.scrollInventory();
    }

    @Override
    public void useActiveItem(UseActiveItemCommand useActiveItemCommand) {
        replay.activeItemUsed();
        model.useActiveItem();
    }

    @Override
    public void saveReplay(File file) {
        replay.saveReplay(file);
    }

}
